package com.rimi.lzhg.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.rimi.lzhg.dao.UserMapper;
import com.rimi.lzhg.entry.User;
import com.rimi.lzhg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

public class ExcelReaderListener extends AnalysisEventListener {

    private UserService userService;

    public ExcelReaderListener(UserService userService){
        this.userService=userService;
    }

    private List<String> warrings=new ArrayList<>();

    @Override
    public void invoke(Object o, AnalysisContext analysisContext) {
        User user=(User) o;
        if(user!=null){
            user.setPassword("123456");
        }
        boolean isok = userService.register(user);
        if(!isok){
            warrings.add("第"+analysisContext.getCurrentRowNum()+"添加失败");
        }
    }

    //所有的内容全部解析完毕
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

}
